/**
 * 
 */
package org.cst.ming.android.barcode;


import java.util.Hashtable;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;


/**
 * @author Ming
 * 
 */
public final class BarcodeWriter
{
	private BarcodeWriter()
	{
		throw new UnsupportedOperationException("Static class should not be instantiate.");
	}

	public static BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
			throws WriterException
	{
		return new MultiFormatWriter().encode(contents, format, width, height);
	}

	public static BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Hashtable<?, ?> hints)
			throws WriterException
	{
		return new MultiFormatWriter().encode(contents, format, width, height, hints);
	}

	public static Bitmap toBitmap(BitMatrix bitMatrix)
	{
		final int width = bitMatrix.width;
		final int height = bitMatrix.height;
		final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

		for (int x = 0; x < width; x++)
		{
			for (int y = 0; y < height; y++)
			{
				bitmap.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
			}
		}

		return bitmap;
	}
}
